﻿using System.Threading;

namespace SS.Server.ReceiveFilter
{

    using SuperSocket.Common;
    using SuperSocket.Facility.Protocol;
    using SuperSocket.SocketBase.Protocol;
    using System;

    public class FixedHeaderBytesReceivePackageConverter : FixedHeaderReceiveFilter<BinaryRequestInfo>
    {
        public FixedHeaderBytesReceivePackageConverter()
            : base(4)
        {

        }

        protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
        {
            return BitConverter.ToInt32(header, offset);
        }

        protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header,byte[] bodyBuffer,int offset,int length)
        {
            return new BinaryRequestInfo(BitConverter.ToInt16(bodyBuffer, offset).ToString(),bodyBuffer.CloneRange(offset, length));
        }
    }
}